package com.pattern.prototype;

import java.io.IOException;

/**
 * 原型模式
 * @author LYao15
 */
public class PrototypeTest {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //浅克隆
        User user = new User("张三", 23);
        PrototypePattern p1 = new PrototypePattern(user);
        PrototypePattern p2 = p1.clone();
        // false
        System.out.println(p1 == p2);
        // true
        System.out.println(p1.getUser() == p2.getUser());
        // true
        System.out.println(p1.getAge() == p2.getAge());

        //深克隆
        User user1 = new User("李四", 20);
        PrototypePattern1 p11 = new PrototypePattern1(user1);
        PrototypePattern1 p12 = p11.deepClone();
        // false
        System.out.println(p11 == p12);
        // false
        System.out.println(p11.getUser() == p12.getUser());
        // true
        System.out.println(p11.getAge() == p12.getAge());
    }
}
